/*
 * SPDX-License-Identifier:	GPL-2.0+
 */

/*
 * This file contains the configuration parameters for the ls2k pc board.
 */

#ifndef __CONFIG_H
#define __CONFIG_H

#include <asm/sizes.h>

//#define DEBUG  1

#define CONFIG_MIPS32		1	/* MIPS 4Kc CPU core	*/
#define CONFIG_LOONGSON2_SOC
#define CONFIG_CPU_LOONGSON2K
#define CONFIG_BOARD_NAME	"ls2k1000 pai"
#define CONFIG_BOARD_LS2K_PAI

/* Loongson bootelf bootparam smbios */
#define CONFIG_LOONGSON_BOARD_NAME CONFIG_BOARD_NAME
#define CONFIG_LOONGSON_BOOTELF
#define CONFIG_SMBIOS_PRODUCT_NAME "Loongson 2K1000"
#define CONFIG_SMBIOS_MANUFACTURER "Loongson"

#define OSC_CLK			100000000 //LS2K使用内部参考时钟100MHz（固定）

#define CPU_CLOCK_RATE	900000000	/* 定义cpu核心频率为1000 MHz */
#define DDR_CLOCK_RATE	450000000	/* 定义ddr频率为450 MHz */
#define APB_CLOCK_RATE	125000000	/* 定义apb频率为125 MHz，目前固定为125MHz */
#define CPU_TCLOCK_RATE CPU_CLOCK_RATE
#define CONFIG_SYS_MIPS_TIMER_FREQ	(CPU_TCLOCK_RATE / 2)
#define CONFIG_SYS_HZ			1000

/* Cache Configuration */
#define CONFIG_SYS_DCACHE_SIZE		(32*1024)
#define CONFIG_SYS_ICACHE_SIZE		(32*1024)
#define CONFIG_SYS_CACHELINE_SIZE	64

/* Miscellaneous configurable options */
#define CONFIG_SYS_MAXARGS		16	/* max number of command args*/
#define CONFIG_SYS_LONGHELP		/* undef to save memory	     */
#define CONFIG_SYS_PROMPT "=> "
#define CONFIG_SYS_CBSIZE		512 /* Console I/O Buffer Size   */
#define CONFIG_SYS_PBSIZE		(CONFIG_SYS_CBSIZE + sizeof(CONFIG_SYS_PROMPT) + 16) /* Print Buffer Size */

#define CONFIG_SYS_MONITOR_BASE	CONFIG_SYS_TEXT_BASE

#define CONFIG_SYS_MALLOC_LEN		(8 * 1024 * 1024)
#define CONFIG_SYS_BOOTPARAMS_LEN	(128 * 1024)

/* memory */
#define CONFIG_SYS_SDRAM_BASE		0x80000000	/* Cached addr */
#define CONFIG_SYS_INIT_SP_OFFSET	0x00040000
#define CONFIG_SYS_LOAD_ADDR		0x82000000
#define CONFIG_SYS_MEMTEST_START	0x80100000
#define CONFIG_SYS_MEMTEST_END		0x80800000
#define CONFIG_MEM_SIZE SZ_256M
#define CONFIG_SYS_SDRAM_SIZE		SZ_2G

//#define CONFIG_STACKSIZE		(256 << 10)

#define CONFIG_SYS_MIPS_CACHE_MODE CONF_CM_CACHABLE_NONCOHERENT

/* misc settings */
#define CONFIG_BOARD_EARLY_INIT_F 1	/* call board_early_init_f() */
#define CONFIG_INCA_IP	//调用incaip_set_cpuclk()函数，设置cpu频率及总线频率等

/* GPIO */
#define CONFIG_LS2X_GPIO

/* Boot beep */
#define BEEP_GPIO 39
#define BEEP_DEBUG_GPIO BEEP_GPIO	//用于启动过程的提示音

/* UART */
#define CONFIG_PRINTK
#define CONFIG_CPU_UART
#define CONFIG_BAUDRATE			115200
#define CONFIG_CONS_INDEX	1

#define CONFIG_SYS_NS16550
#define CONFIG_SYS_NS16550_SERIAL
#define CONFIG_SYS_NS16550_REG_SIZE	 1
#define CONFIG_SYS_NS16550_CLK	 0
#define CONFIG_SYS_NS16550_COM1	 0xbfe00000
#define UART_BASE_ADDR	CONFIG_SYS_NS16550_COM1

/* SPI Settings */
#define CONFIG_LS1X_SPI
//#define CONFIG_LS1X_SPI1_ENABLE	/* 使用spi1控制器(复用设置), spi1控制器复用can，如果不使用spi1，最好把该选项关闭 */
#define CONFIG_SPI_CS
//#define CONFIG_SPI_CS_USED_GPIO
#define CONFIG_SF_DEFAULT_CS 0
#define CONFIG_SF_DEFAULT_SPEED	30000000
#define CONFIG_SPI_FLASH
#define CONFIG_SPI_FLASH_WINBOND
#define CONFIG_SPI_FLASH_GIGADEVICE
#define CONFIG_SPI_FLASH_SST
#define CONFIG_SPI_FLASH_EON
#define CONFIG_SPI_FLASH_STMICRO
#define CONFIG_CMD_SF
#define CONFIG_CMD_SPI

/* Flash Settings */
#define CONFIG_SYS_NO_FLASH	1

/* Env Storage Settings */
//#define CONFIG_ENV_IS_IN_NVRAM
#define CONFIG_ENV_IS_IN_SPI_FLASH
#if defined(CONFIG_ENV_IS_IN_NVRAM)
#define CONFIG_ENV_ADDR		0x9fc40000
#define CONFIG_ENV_SIZE		0x4000
#elif defined(CONFIG_ENV_IS_IN_SPI_FLASH)
#define CONFIG_ENV_SPI_CS	0
#define CONFIG_ENV_SPI_MAX_HZ	30000000
#define CONFIG_ENV_OFFSET	0x80000
#define CONFIG_ENV_SIZE		0x4000	/* 16KB */
#define CONFIG_ENV_SECT_SIZE	256
#endif

#define CONFIG_EXTRA_ENV_SETTINGS \
	"loadaddr=" __stringify(CONFIG_SYS_LOAD_ADDR) "\0" \
	"pciconfighost=1\0" \
	"serverip=192.168.1.2\0" \
	"ipaddr=192.168.1.20\0" \
	"ethaddr=10:84:7F:B5:9D:FC\0" \
	"panel=" "vesa1920x1080@60" "\0" \

/* RTC configuration */
//#define CONFIG_RTC_LS1X
#define CONFIG_RTC_TOY_LS1X
#define CONFIG_CMD_DATE

/* File System Support */
#define CONFIG_CMD_EXT2
#define CONFIG_CMD_EXT4
#define CONFIG_CMD_FAT
#define CONFIG_DOS_PARTITION
#define CONFIG_SUPPORT_VFAT
#define CONFIG_FAT_WRITE
//#define CONFIG_CMD_UBIFS	//uboot会增加100KB多的大小
#if defined(CONFIG_CMD_UBIFS)
#define CONFIG_CMD_UBI
#define CONFIG_RBTREE
#endif
#define CONFIG_LZO
#define CONFIG_LZMA
#define CONFIG_BZIP2

/* Ethernet driver configuration */
#define CONFIG_LS2X_GMAC
#define ENH_DESC //ls2x的gmac控制器需要把该宏定义打开
#define CONFIG_NET_MULTI
#define CONFIG_NET_RETRY_COUNT          5

/* PCI */
#define CONFIG_PCIE_LOONGSON2_SOC
#define CONFIG_PCI
#define CONFIG_CMD_PCI
#define CONFIG_PCI_PNP
#define CONFIG_PCI_CONFIG_HOST_BRIDGE
#define CONFIG_PCI_SCAN_SHOW

/* Framebuffer and LCD */
#define CONFIG_VIDEO
#define CONFIG_VIDEO_LS1X
//#define CONFIG_LS1X_DC0
//#define CONFIG_LS1X_DC0_USE_DEMODE
#define CONFIG_LS1X_DC1
//#define CONFIG_LS1X_DC1_USE_DEMODE
#define VIDEO_FB_16BPP_WORD_SWAP
#define CONFIG_SPLASH_SCREEN
#define CONFIG_SPLASH_SCREEN_ALIGN
#define CONFIG_CFB_CONSOLE
#define CONFIG_VGA_AS_SINGLE_DEVICE
#define CONFIG_SYS_CONSOLE_IS_IN_ENV
#define DEFAULT_FB_SIZE	(1920 * 1080 * 4)
/*#define CONFIG_CONSOLE_MUX*/ /* 可以同时输出到lcd和串口的 */
#define CONFIG_VIDEO_LOGO
/*
#define CONFIG_VIDEO_BMP_RLE8
#define CONFIG_VIDEO_BMP_LOGO*/
#define CONFIG_BMP_16BPP
#define CONFIG_BMP_24BPP
#define CONFIG_BMP_32BPP
#define CONFIG_CMD_BMP
/* lcd背光或供电控制 /board/ls1x/ls1x_video.c文件中lcd控制器初始化后使能背光 */
//#define CONFIG_BACKLIGHT_GPIO 28	//gpio号

/* I2C settings */
#define CONFIG_LS1X_I2C
#define CONFIG_LS1X_I2C0
#define CONFIG_LS1X_I2C1
#define CONFIG_I2C_MULTI_BUS
#define CONFIG_SYS_MAX_I2C_BUS		2
#define CONFIG_HARD_I2C		1
#define CONFIG_SYS_I2C_SPEED		400000
#define CONFIG_SYS_I2C_SLAVE		0
#define CONFIG_CMD_I2C

#ifdef CONFIG_HARD_I2C
#define CONFIG_SII9022A
#define CONFIG_SYS_I2C_SII9022A_ADDR	0x39
#endif

/* SCSI */
#define CONFIG_SCSI_AHCI
#ifdef CONFIG_SCSI_AHCI
#define CONFIG_LIBATA
#define CONFIG_SCSI_AHCI_201605
#define SCSI_VEND_ID 0x0014
#define SCSI_DEV_ID  0x7a08
#define CONFIG_SCSI_AHCI_PLAT
#define CONFIG_AHCI_SETFEATURES_XFER
#define CONFIG_SYS_SCSI_MAX_SCSI_ID	1
#define CONFIG_SYS_SCSI_MAX_LUN	1
#define CONFIG_SYS_SCSI_MAX_DEVICE	(CONFIG_SYS_SCSI_MAX_SCSI_ID * CONFIG_SYS_SCSI_MAX_LUN)
#define CONFIG_SYS_SCSI_MAXDEVICE	CONFIG_SYS_SCSI_MAX_DEVICE
#define CONFIG_CMD_SCSI
#endif

/*
 * Command line configuration.
 */
#include <config_cmd_default.h>
#define CONFIG_CMDLINE_EDITING			/* add command line history	*/
#define CONFIG_AUTO_COMPLETE

#define CONFIG_CMD_ELF
#define CONFIG_CMD_NET
#define CONFIG_CMD_MII
#define CONFIG_CMD_PING
#define CONFIG_CMD_TFTPPUT
#define CONFIG_CMD_DHCP
#define CONFIG_CMD_NFS

/* Other helpful shell-like commands */
#define CONFIG_MD5
#define CONFIG_CMD_MD5SUM

#define CONFIG_SYS_BOOTM_LEN	SZ_64M	/* max gunzip size */
#define CONFIG_BOOTDELAY	0		/* Autoboot after 0 seconds	*/
#define CONFIG_ZERO_BOOTDELAY_CHECK
#define CONFIG_AUTOBOOT_KEYED
#define CONFIG_AUTOBOOT_PROMPT "Press 'c' into Cmdline or 'm' into Menu\r\n"
#define CONFIG_AUTOBOOT_STOP_STR "c" /* 启动时按c进入命令行 */
#define CONFIG_AUTOBOOT_DELAY_STR "m" /* 启动时按m进入菜单栏 */
#define CONFIG_BOOTCOMMAND	"tftpboot ${loadaddr} uImage\;bootm ${loadaddr}"	/* Autoboot command	*/
//#define CONFIG_BOOTCOMMAND	"nboot kernel\;bootm" /* 注意： nboot默认加载地址为CONFIG_SYS_LOAD_ADDR，CONFIG_SYS_LOAD_ADDR要与bootm的地址一致 */
#define CONFIG_BOOTARGS		"console=ttyS0,115200 rdinit=/sbin/init video=ls1xfb:1920x1080-16@60"


#define CONFIG_TIMESTAMP		/* Print image info with timestamp */
//#define CONFIG_SHOW_BOOT_PROGRESS	//打印uboot启动进度信息，用于调试

#define CONFIG_DMA_COHERENT 1

#define CONFIG_ARCH_EARLY_INIT_R
#define CONFIG_MISC_INIT_R
//#define ARCH_DMA_MINALIGN CONFIG_SYS_CACHELINE_SIZE
//#define CONFIG_CMD_BOOTK


/* ls2k ddr配置 */
#define DDR3_DIMM
#define LSMC_2
#define DDR_PARAM_018 0x4545454516100000
#define DDR_FREQ DDR_CLOCK_RATE/1000000

//#define TEMP_EXTREME
#define  DISABLE_DDR_A15
//#define NO_AUTO_TRFC

//#define ARB_LEVEL
//#define AUTO_DDR_CONFIG

#define CONFIG_DDR_16BIT
#define DDR_RESET_REVERT

#define DDR_PARAM_NUM   110 //内存条定义了LSMC_2 DDR_PARAM_NUM=116
#if 1
#define DDR_S1 0xc1a18404
#else
#define DDR_S1 ( MC_SDRAM_TYPE_DDR3    /* sdram type: DDR3/DDR2 */ \
		| MC_DIMM_ECC_NO        /* dimm ECC: YES/NO */ \
		| MC_DIMM_BUF_REG_NO    /* dimm buffer register: YES/NO, for RDIMM use YES, all else use NO*/ \
		| MC_DIMM_WIDTH_64      /* memory data width: 64/32 */ \
		| MC_SDRAM_ROW_15       /* sdram row address number: 15~11 */ \
		| MC_SDRAM_COL_10       /* sdram column address number: 12~9 */ \
		| MC_SDRAM_BANK_8       /* sdram bank number: 8/4 */ \
		| MC_ADDR_MIRROR_NO    /* for standard DDR3 UDIMM, use YES, else use NO */ \
		| MC_SDRAM_WIDTH_X16     /* SDRAM device data width: 8/16 */ \
		| MC_USE_CS_0         /* the CS pins the sdram connected on(split by '_', from small to big) */ \
		| MC_MEMSIZE_(8)        /* MC memory size, unit: 512MB */ \
		| USE_MC_0)
#endif

#endif	/* __CONFIG_H */
